import {
		mapGetters
} from 'vuex';
import {
	toast,
	useRouter
} from '@/request/utils.js' // 公共方法
const mixin = {
	data() {
		return {

		}
	},
	computed: {
		...mapGetters(['isLogin','userInfo'])
	},
	methods: {
		// 'navigateTo' | 'redirectTo' | 'reLaunch' | 'switchTab' | 'navigateBack' | number
		goToPage(path, type="navigateTo", params = {}) {
			if(!this.isLogin){
				useRouter('/pages/login/login');
			}else{
				useRouter(path, type, params);
			}
		},
		goToNoLoginPage(path, type="navigateTo", params = {}){
			useRouter(path, type, params);
		},
		// 验券扫码
		scanQrcode(){
			uni.scanCode({
			  onlyFromCamera: false,
			  success (res) {
				// console.log("扫描内容",res.result)
				// console.log("rawData",res.rawData)
			  }
			})
		},
		// 授权 scope授权域
		queryAuthorize(scope='',callBack){
			
			// 先查询是否弹出过授权弹窗
			// 否 => 弹出授权弹窗
			// 是 => 同意授权 => 直接调用接口
			// 		=> 拒绝授权 => 打开授权设置页面
			uni.getSetting({
			  success:(res)=> {
					let curScope = res.authSetting[scope||'scope.writePhotosAlbum'];
					if(curScope===true){
						// 已同意授权 直接调用接口
						console.log('调用接口')
						callBack&&callBack();
					}
					else if(curScope===false){
						// 已拒绝授权 直接调用接口
						uni.openSetting({
							withSubscriptions: false,
						  success: (res)=> {
						    console.log('aaa',res.authSetting)
								
						    // res.authSetting = {
						    //   "scope.userInfo": true,
						    //   "scope.userLocation": true
						    // }
						  },
							fail:(err)=> {
						    console.log('bbb',err)
						  }
						})
					}else{
						// 未授权
						uni.authorize({
						  scope: scope||'scope.writePhotosAlbum',
						  success: (dd)=> {
								console.log(123,dd)
								// 同意授权 直接调用接口
								console.log('调用接口')
								callBack&&callBack();
						  },
							fail:(err)=>{
								console.log(456,err)
							}
						})
					}
			  }
			});
		}
	}
}

export default mixin;
